//
//  UIImage+Extension.m
//  KaCha
//
//  Created by qishi on 15/8/3.
//  Copyright (c) 2015年 qisi. All rights reserved.
//

#import "UIImage+Extension.h"
#import "NSString+File.h"

@implementation UIImage (Extension)
#pragma mark 根据屏幕尺寸返回全屏的图片
+ (UIImage *)fullscreenImageWithName:(NSString *)name
{
    if (iPhone5) {
        name = [name filenameAppend:@"-568h@2x"];
    }
    if (iPhone6) {
        name =[name filenameAppend:@"-667h@2x"];
    }
    if (iPhone6p) {
        name =[name filenameAppend:@"-736h@3x"];
    }
    return [UIImage imageNamed:name];
}

+ (UIImage *)stretchImageWithName:(NSString *)name
{
    UIImage *image = [UIImage imageNamed:name];
    
    return [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
}
+ (UIImage *)stretchImageHeightWithName:(NSString *)name
{
    UIImage *image = [UIImage imageNamed:name];
    
    return [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.4];
}
+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end
